package com.thread.exem;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author げっしょく
 * @date 2021/8/6
 */
public class Test3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCall myCall = new MyCall();
        FutureTask<String> s = new FutureTask<>(myCall);
        Thread t1 = new Thread(s);
        t1.start();
        String s1 = s.get();
        System.out.println(s1);

    }
}


class
MyCall implements Callable<String>{

    @Override
    public String call() throws Exception {
        Random r = new Random();
        int a ;
        for (int i = 0; i < 100; i++) {
            System.out.println("表白" + (i + 1) + "次");
            a = r.nextInt(100) +1;
            if(a == 50){
                return "表白成功！！！";
            }
        }
        return "女孩报警！！！";
    }
}